package com.yanqu.road.server.cmd.activity.unionwar;


import com.yanqu.road.entity.activity.ActivityRewardResult;
import com.yanqu.road.pb.activity.unionwar.UnionWarActivityServerProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.unionwar.UnionWarActivityModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_UNION_WAR_RESULT_GET_USER_REWARD,desc = "战斗结果奖励(如轮空时主动领取)")
public class UnionWarGetBattleRewardCmd extends AbstractCommand {

    private int activityId;
    private int phase;
    private int session;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        UnionWarActivityServerProto.UserGetBattleRewardReqMsg reqMsg = UnionWarActivityServerProto.UserGetBattleRewardReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        phase = reqMsg.getPhase();
        session = reqMsg.getSession();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        //下发奖励
        ActivityRewardResult result = player.getModule(UnionWarActivityModule.class).getBattleResultReward(activityId, phase, session);
        UnionWarActivityServerProto.UserGetBattleRewardSyncMsg.Builder respMsg = UnionWarActivityServerProto.UserGetBattleRewardSyncMsg.newBuilder();
        respMsg.setReward(result.getReward());
        respMsg.setActivityId(activityId);
        respMsg.setPhase(phase);
        respMsg.setRet(result.getRet());
        respMsg.setSession(session);
        player.sendPacket(Protocol.U_UNION_WAR_RESULT_GET_USER_REWARD, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
